import request from '@/utils/request';
import config from '@/env/config';
import { IResume, IWork } from '@/types';

/**
 * 阿姨自己查看简历接口
 * @returns string
 */
export function getUserResume(): Promise<IResume> {
  return request({
    method: 'post',
    url: `${config.SERVICE_API}api/user/resume/query`,
    isTransformResponse: true,
  }).then((v: { code: number; data: IResume }) => {
    if (v.code !== 103) {
      v.data.certificateList = v.data.certificate?.split(',') || [];
      return v.data;
    }
    throw new Error('登录信息已失效');
  });
}

/**
 * 阿姨修改简历接口
 * @returns string
 */
export function updateUserResume(data): Promise<IResume> {
  return request({
    method: 'post',
    data,
    url: `${config.SERVICE_API}api/user/resume/update`,
  });
}

/**
 * 查询所有工作经历
 * @returns string
 */
export function getWorks(data): Promise<IWork[]> {
  return request({
    method: 'post',
    data,
    url: `${config.SERVICE_API}api/user/works/query`,
  });
}

/**
 * 查询单个工作经历
 * @returns string
 */
export function getWork(data): Promise<IWork> {
  return request({
    method: 'post',
    data,
    url: `${config.SERVICE_API}api/user/work/query`,
  });
}

/**
 * 修改工作经历
 * @returns string
 */
export function updateWork(data): Promise<void> {
  return request({
    method: 'post',
    data,
    url: `${config.SERVICE_API}api/user/work/update`,
  });
}

/**
 * 删除工作经历
 * @returns string
 */
export function delWork(data): Promise<void> {
  return request({
    method: 'post',
    data,
    url: `${config.SERVICE_API}api/user/work/del`,
  });
}
